package ink.onei.shopping.service.impl;

import java.util.List;

import ink.onei.shopping.domain.Detail;
import ink.onei.shopping.domain.Goods;
import ink.onei.user.domain.Client;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ink.onei.shopping.mapper.CommentMapper;
import ink.onei.shopping.domain.Comment;
import ink.onei.shopping.service.ICommentService;

/**
 * 商品评论Service业务层处理
 * 
 * @author nekotako
 * @date 2024-02-05
 */
@Service
public class CommentServiceImpl implements ICommentService  {
    @Autowired
    private CommentMapper commentMapper;

    /**
     * 查询商品评论
     * 
     * @param commentId 商品评论主键
     * @return 商品评论
     */
    @Override
    public Comment selectCommentByCommentId(Long commentId) {
        return commentMapper.selectCommentById(commentId);
    }

    /**
     * 查询商品评论列表
     * 
     * @param comment 商品评论
     * @return 商品评论
     */
    @Override
    public List<Comment> selectCommentList(Comment comment) {
        Goods goods = comment.getGoods();
        goods = goods == null ? new Goods() : goods;
        comment.setGoods(goods);

        Detail detail = comment.getDetail();
        detail = detail == null ? new Detail() : detail;
        comment.setDetail(detail);


        Client client = comment.getClient();
        client = client == null ? new Client() : client;
        comment.setClient(client);

        return commentMapper.selectCommentList(comment);
    }

    /**
     * 新增商品评论
     * 
     * @param comment 商品评论
     * @return 结果
     */
    @Override
    public int insertComment(Comment comment) {
        return commentMapper.insertComment(comment);
    }

    /**
     * 修改商品评论
     * 
     * @param comment 商品评论
     * @return 结果
     */
    @Override
    public int updateComment(Comment comment) {
        return commentMapper.updateComment(comment);
    }

    /**
     * 批量删除商品评论
     * 
     * @param commentIds 需要删除的商品评论主键
     * @return 结果
     */
    @Override
    public int deleteCommentByCommentIds(Long[] commentIds) {
        return commentMapper.deleteCommentByIds(commentIds);
    }

    /**
     * 删除商品评论信息
     * 
     * @param commentId 商品评论主键
     * @return 结果
     */
    @Override
    public int deleteCommentByCommentId(Long commentId) {
        return commentMapper.deleteCommentById(commentId);
    }
}
